/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package processamento;

import java.awt.image.ColorModel;
import java.awt.image.Raster;
import java.awt.image.SampleModel;
import java.awt.image.WritableRaster;
import java.awt.image.renderable.ParameterBlock;
import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
import javax.media.jai.TiledImage;

/**
 *
 * @author Igor
 */
public class SubtracaoImagens {

        public PlanarImage subtraiImagens(PlanarImage pi, PlanarImage pi2) {
            /*int width = pi.getWidth();
            int height = pi.getHeight();

            Raster inputRaster2 = pi2.getData();
            Raster inputRaster = pi.getData();

            WritableRaster outputRaster = inputRaster.createCompatibleWritableRaster();

            int[] pixels = new int[1 * width * height]; //sempre grayscale
            int[] pixels2 = new int[1 * width * height]; //sempre grayscale

            inputRaster.getPixels(0, 0, width, height, pixels);
            inputRaster2.getPixels(0, 0, width, height, pixels2);

            for(int i =0; i < pixels.length; i++)
            {
                int now = (int)pixels[i] & 0xff;
                int before = (int)pixels2[i] & 0xff;

                pixels[i] = Math.abs(before-now);
                
            }

            outputRaster.setPixels(0, 0, width, height, pixels);
            TiledImage ti = new TiledImage(pi, width, height);
            ti.setData(outputRaster);
            System.out.println("---------------------------");
            return ti;*/


            ParameterBlock pbSubtracted = new ParameterBlock();

            pbSubtracted.addSource(pi);
            pbSubtracted.addSource(pi2);

            PlanarImage finalImage = JAI.create("subtract",pbSubtracted);
            return finalImage;
        }

    public PlanarImage adicionaImagens(PlanarImage imgProcessada, PlanarImage imgAuxiliar) {
         ParameterBlock pbSubtracted = new ParameterBlock();

            pbSubtracted.addSource(imgProcessada);
            pbSubtracted.addSource(imgAuxiliar);

            PlanarImage finalImage = JAI.create("and",pbSubtracted);
            return finalImage;
    }
}
